/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wasolicitudesfiec.dataproviders;

import com.sun.data.provider.DataProviderException;
import com.sun.data.provider.FieldKey;
import com.sun.data.provider.RowKey;
import com.sun.data.provider.impl.AbstractTableDataProvider;
import com.sun.data.provider.impl.IndexRowKey;
import entidad.Rol;
import java.util.ArrayList;
/**
 *
 * @author kabad
 */
public class Dp_Roles extends AbstractTableDataProvider {
  //registro
    private ArrayList<Rol> listaRg_Rol = new ArrayList<Rol>();

    public Dp_Roles() {
        FieldKey key;
        key = new FieldKey("id");
        key.setDisplayName("id");
        addFieldKey(key);

        key = new FieldKey("nombre");
        key.setDisplayName("Nombre");
        addFieldKey(key);

        key = new FieldKey("descripcion");
        key.setDisplayName("Descripcion");
        addFieldKey(key);
    }

    @Override
    public Class getType(FieldKey fieldKey) throws DataProviderException {
        if (fieldKey.getFieldId().equals("id")) {
            return (new Integer(1)).getClass();
        } else {
            return (new String()).getClass();
        }
    }

    @Override
    public boolean isReadOnly(FieldKey fieldKey) throws DataProviderException {
        return false;
    }

    @Override
    public int getRowCount() throws DataProviderException {
        return this.getListaRg_Rol().size();
    }

    @Override
    public Object getValue(FieldKey fieldKey, RowKey row) throws DataProviderException {
        int indice = ((IndexRowKey) row).getIndex();
        Rol registro = (Rol) this.getListaRg_Rol().get(indice);
		if (fieldKey==null)
			return "";
		String fieldId = fieldKey.getFieldId();
        if (fieldId.equals("nombre")) {
            return registro.getRol() == null ? "No Disponible" : registro.getRol();

        } else if (fieldId.equals("descripcion")) {
            return registro.getDescripcion() == null ? "No Disponible" : registro.getDescripcion();
        } else if (fieldId.equals("id")) {
            return registro.getIdRol() == 0 ? "No Disponible" : registro.getIdRol();
        } else {
            return registro.getRol();
        }
    }

    @Override
    public void setValue(FieldKey fieldKey, RowKey row, Object value) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canInsertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey insertRow(RowKey beforeRow) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canAppendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public RowKey appendRow() throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean canRemoveRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeRow(RowKey row) throws DataProviderException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
  
    public ArrayList<Rol> getListaRg_Rol() {
        return listaRg_Rol;
    }

    public void setListaRg_Rol(ArrayList<Rol> listaRg_Rol) {
        this.listaRg_Rol = listaRg_Rol;
    }
}
